今天是30天程式語言研究的第二十七天,由於最近寫unix語言的東西用到很多,所以做了很多筆記,就想說也分享給大家。
筆記:
export:
export (-p)     顯示所有環境變數(-p可不加)
export ...      把...加入環境變數(下次登入會消失)
ex. export apple=1     //apple=1會暫時加入環境變數內
export -n ...    移除
ex. export -n apple=1
ex.
a=apple          把a設為自訂變數
echo $a          顯示自訂變數apple
vi x             建檔案x輸入echo $a檔案x輸入echo $a
chmod u=wrx x    把x轉成執行檔
./x              在x內(子程式)無法顯示a
export a=apple   把a加入環境變數
./x              顯示apple
export -n a      將a從環境變數移除
echo $a          顯示apple
./x              無法顯示a
export -f ...         用function輸出
ex. export a=/home/       想延伸a
export a="$a"user/   結果=> a=/home/user/
在子程序做的任何環境變數更動,都只存在子程序,回到父程序就無效
find:
find -name name1     搜尋檔案/目錄
find -iname name1     (不分大小寫搜尋)
whereis:
whereis dir     若檔案存在則顯示檔案位置, 若不存在僅顯示dir:
whereis     顯示搜尋那些目錄(whereis不是搜尋所有目錄所以速度比find快)
PATH=$PATH:/home/user     將:/home/user加入whereis 搜索範圍